﻿$(function () {
    window.App = new Vue({
        el: "#app",
        data: {
            ApplyDate: null,
            Title: "",
            Remark: "",
            CompanyId: "",
            CompanyName: ""
        },
        methods: {
            SAVE_CLICK: function () {
                var that = this;
                if (that.ApplyDate == null) {
                    alert("请填写周期");
                    return;
                }
                if (that.Title == "") {
                    alert("请填写编制依据");
                    return;
                }
                if (that.Remark == "") {
                    alert("请填写备注");
                    return;
                }
                try {
                    var result = window.Helper.Api.ApplyMonth({
                        ApplyDate: that.ApplyDate,
                        Title: that.Title,
                        Remark: that.Remark
                    });
                    if (result.Type == 1) {
                        alert("申请成功");
                    }
                    else {
                        alert("申请失败：原因" + result.Msg);
                    }
                } catch (e) {
                    alert("申请异常");
                }
            },
            INIT: function () {
                var that = this;
                that.ApplyDate = new Date();

                that.CompanyId = window.Helper.Current.User.USER_COMPANY.toString();
                that.CompanyName = window.Helper.Current.Company.Name;
                that.Title = that.ApplyDate.format("yyyy年M月") + "资金计划(" + that.CompanyName + ")";
            }
        },
        watch: {
            ApplyDate: function (val) {
                var that = this;
                if (val != null) {
                    that.ApplyDate = val;
                    that.Title = that.ApplyDate.format("yyyy年M月") + "资金计划(" + that.CompanyName + ")";
                }
                else {
                    //console.log("xx");
                }
            }
        },
        mounted: function () {
            this.INIT();
        }
    })
});